﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess;
using EntityDaoLibrary;
using System.Data;
using System.Collections;

namespace BusinessRules
{
    public class YBZLInfoRules
    {

        public YBZLInfoRules()
        {
        }


        #region 业务规则层操作

        public void insertEntity(DataSet entityData)
        {
            IDataAccess data = DataAccessFactory.instance.CreateDataAccess();
            data.Open();
            SingleTransaction tran = new SingleTransaction(data);
            tran.Begin();
            try
            {
                YBZLInfoDAO dao = new YBZLInfoDAO(data);
                dao.insertEntity(entityData);
                tran.Commit();
            }
            catch (Exception e)
            {
                tran.Rollback();
                throw new Exception(e.Message, e);
            }
            finally
            {
                data.Close();
            }
        }


        public void updateEntity(DataSet entityData)
        {
            IDataAccess data = DataAccessFactory.instance.CreateDataAccess();
            data.Open();
            SingleTransaction tran = new SingleTransaction(data);
            tran.Begin();
            try
            {
                YBZLInfoDAO dao = new YBZLInfoDAO(data);
                dao.updateEntity(entityData);
                tran.Commit();
            }
            catch (Exception e)
            {
                tran.Rollback();
                throw new Exception(e.Message, e);
            }
            finally
            {
                data.Close();
            }
        }


        public void deleteEntity(DataSet entityData)
        {
            IDataAccess data = DataAccessFactory.instance.CreateDataAccess();
            data.Open();
            SingleTransaction tran = new SingleTransaction(data);
            tran.Begin();
            try
            {
                YBZLInfoDAO dao = new YBZLInfoDAO(data);
                dao.deleteEntity(entityData);
                tran.Commit();
            }
            catch (Exception e)
            {
                tran.Rollback();
                throw new Exception(e.Message, e);
            }
            finally
            {
                data.Close();
            }
        }


        public DataSet FindByPrimaryKey(object strKeyValue)
        {
            IDataAccess data = DataAccessFactory.instance.CreateDataAccess();
            data.Open();
            try
            {
                YBZLInfoDAO dao = new YBZLInfoDAO(data);
                return dao.FindByPrimaryKey(strKeyValue);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
            finally
            {
                data.Close();
            }
        }


        public DataSet FindByPrimaryKey(ArrayList KeyValue)
        {
            IDataAccess data = DataAccessFactory.instance.CreateDataAccess();
            data.Open();
            try
            {
                YBZLInfoDAO dao = new YBZLInfoDAO(data);
                return dao.FindByPrimaryKey(KeyValue);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
            finally
            {
                data.Close();
            }
        }

        #endregion


        public DataSet FindAll()
        {
            IDataAccess data = DataAccessFactory.instance.CreateDataAccess();
            data.Open();
            try
            {
                YBZLInfoDAO dao = new YBZLInfoDAO(data);
                return dao.FindAll();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
            finally
            {
                data.Close();
            }
        }


        public void deleteEntity()
        {
            IDataAccess data = DataAccessFactory.instance.CreateDataAccess();
            data.Open();
            SingleTransaction tran = new SingleTransaction(data);
            tran.Begin();
            try
            {
                YBZLInfoDAO dao = new YBZLInfoDAO(data);
                dao.deleteEntity();
                tran.Commit();
            }
            catch (Exception e)
            {
                tran.Rollback();
                throw new Exception(e.Message, e);
            }
            finally
            {
                data.Close();
            }
        }
    }
}
